package com.yumeko.zkclient;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;

/**
 * @program: zookeeper
 * @description:
 * @author: Zheng Hao
 * @create: 2020-03-26 14:18
 */
public class GetNode {
    public static void main(String[] args) throws InterruptedException {
        ZkClient zkClient = new ZkClient("192.168.106.128:2183", 3000, 5000);
        List<String> children = zkClient.getChildren("/RecursiveCreate");
        System.out.println(children);
        //注册监听事件
        zkClient.subscribeChildChanges("/RecursiveCreate-get", new IZkChildListener() {
            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                System.out.println(parentPath + " 's child changed,currentChilds:" + currentChilds);
            }
        });
        zkClient.createPersistent("/RecursiveCreate-get");
        Thread.sleep(1000);
        zkClient.createPersistent("/RecursiveCreate-get/yumeko1");
        Thread.sleep(1000);
        zkClient.delete("/RecursiveCreate-get/yumeko1");
        Thread.sleep(1000);
        zkClient.delete("/RecursiveCreate-get");
        Thread.sleep(Integer.MAX_VALUE);
    }
}
